<template>
  <view>
    <web-view :src="src"></web-view>
  </view>
</template>
<script setup>
import { onLoad, onShareAppMessage } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { ShareConfig } from "@/campaign/pages/2023airycake/config";
import { ObjectToQueryString } from "@/utils/utils";

const src = ref("");
const locationInfo = reactive({ latitude: "", longitude: "" })

onShareAppMessage(() => ShareConfig())

onLoad((options) => {
  getApp().accessLogAdd();
  uni.getLocation({
    type: "gcj02",
    success: (result) => {
      Object.assign(locationInfo, result)
      console.log('location', result)
    },
    complete() {
      if (options.accesstoken) {
        const source = options.source ? "record" : "index";
        const queryPrams = ObjectToQueryString({
          accesstoken: options.accesstoken,
          code: options.code,
          openid: options.openid,
          unionid: options.unionid,
          memberid: options.memberid,
          agree: true,
          latitude: locationInfo.latitude,
          longitude: locationInfo.longitude
        })
        src.value = `${process.env.CAKE_URL}/a/${source}.html?${queryPrams}`
        console.log('location', src.value)
      }
    },
  });
  // 是否登录注册
  if (
    getApp().globalData.user.phone === null ||
    getApp().globalData.user.phone === ""
  ) {
    uni.navigateTo({ url: "/pages/vip/register?tag=scanCode" });
    return;
  }
  console.log(src.value);
})
</script>

<style></style>
